$(function(){
	 $("#gridPage").mobileGrid();	
	 $("#search").bind("tap",function(){
		 var searchName=$("#searchName").val();
		 $("#gridPage").search({searchName:searchName});
	 });
	 $("#home").bind("tap",toHome);
});
function image(cell,data){
	var html='<a onclick=goTo('+data.id+')><img src="'+data.image+'" /></a>';
	cell.html(html);
}
function name(cell,data){
	var html='<a onclick=goTo('+data.id+')>'+data.name+'</a>';
	cell.html(html);
}
function price(cell,data){
	var html='<a onclick=goTo('+data.id+')>'+data.price+'</a>';
	cell.html(html);
}
function editOrDelete(cell,data){
	var html='<b class="ui-mobile-grid-title">操作</b><a onclick=editRecord("'+data.id+'")><img src="../image/gouwuche_32.png"></img>';
	cell.html(html);
}

function editRecord(id){  
	var userName = sessionStorage['username'];
	if(userName==null||userName==""){
		$(window).mobileMsgBox({msgText:"请先登录",delayTime:1000});
		window.location="login.html#loginPage";
	}else{	
  	   	Newtouch.Ajax.sendParams({productId:id,userId:sessionStorage['userId']},localStorage['APP_AJAX_PATH']+"/drinkingBar/view/search.jsp.addProToCart",function(data){	
		$(window).mobileMsgBox({msgText:"添加购物车成功",delayTime:500});
	},function(err){
		$(window).mobileMsgBox({msgText:"添加购物车失败",delayTime:500});
	});
	}
    
}
function goTo(id){
	androidLocal({"productId":id});
	window.location="productDetail.html";
	
}
function toHome(){
	window.location = "main.html";
}
var androidLocal=function(p){
	for(var k in p){
		sessionStorage[k]=p[k];
	}
}